package com.kxmall.web.controller.huishou;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.kxmall.common.annotation.RepeatSubmit;
import com.kxmall.common.annotation.Log;
import com.kxmall.common.core.controller.BaseController;
import com.kxmall.common.core.domain.PageQuery;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.core.validate.AddGroup;
import com.kxmall.common.core.validate.EditGroup;
import com.kxmall.common.enums.BusinessType;
import com.kxmall.common.utils.poi.ExcelUtil;
import com.kxmall.huishou.domain.vo.HsRecoveryVehicleVo;
import com.kxmall.huishou.domain.bo.HsRecoveryVehicleBo;
import com.kxmall.huishou.service.IHsRecoveryVehicleService;
import com.kxmall.common.core.page.TableDataInfo;

/**
 * 回收车辆信息
 *
 * @author kxmall
 * @date 2023-11-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/huishou/recoveryVehicle")
public class HsRecoveryVehicleController extends BaseController {

    private final IHsRecoveryVehicleService iHsRecoveryVehicleService;

    /**
     * 查询回收车辆信息列表
     */
    @SaCheckPermission("huishou:recoveryVehicle:list")
    @GetMapping("/list")
    public TableDataInfo<HsRecoveryVehicleVo> list(HsRecoveryVehicleBo bo, PageQuery pageQuery) {
        return iHsRecoveryVehicleService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出回收车辆信息列表
     */
    @SaCheckPermission("huishou:recoveryVehicle:export")
    @Log(title = "回收车辆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HsRecoveryVehicleBo bo, HttpServletResponse response) {
        List<HsRecoveryVehicleVo> list = iHsRecoveryVehicleService.queryList(bo);
        ExcelUtil.exportExcel(list, "回收车辆信息", HsRecoveryVehicleVo.class, response);
    }

    /**
     * 获取回收车辆信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("huishou:recoveryVehicle:query")
    @GetMapping("/{id}")
    public R<HsRecoveryVehicleVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iHsRecoveryVehicleService.queryById(id));
    }

    /**
     * 新增回收车辆信息
     */
    @SaCheckPermission("huishou:recoveryVehicle:add")
    @Log(title = "回收车辆信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HsRecoveryVehicleBo bo) {
        bo.setStatus(0l);
        return toAjax(iHsRecoveryVehicleService.insertByBo(bo));
    }

    /**
     * 修改回收车辆信息
     */
    @SaCheckPermission("huishou:recoveryVehicle:edit")
    @Log(title = "回收车辆信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HsRecoveryVehicleBo bo) {
        return toAjax(iHsRecoveryVehicleService.updateByBo(bo));
    }

    /**
     * 删除回收车辆信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("huishou:recoveryVehicle:remove")
    @Log(title = "回收车辆信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iHsRecoveryVehicleService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
